#!/bin/bash
# echo -e "本脚本不建议使用sudo执行\n"

workd=$(cd "$(dirname $0)";pwd)
program=${HOME}/bin
source ./bin/basic_func.sh

black=$'\e[1;30m'
red=$'\e[1;31m'
green=$'\e[1;32m'
yellow=$'\e[1;33m'
blue=$'\e[1;34m'
magenta=$'\e[1;35m'
cyan=$'\e[1;36m'
white=$'\e[1;37m'
normal=$'\e[m'

function installNvimSnap() {
set +e
    sudo snap install nvim --classic
    pip install pynvim
set -e
}


function main() {
set -e

    ## 1.复制能复制的
    echo -e "${hintStrProcessing}Coping configuration files${normal}"
    bash ./bin-for-install/04.copy.sh

    ## 2.换apt源
    bash ./bin-for-install/02.change-apt-sources.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    ## 换桌面文字
    bash ./bin-for-install/05.change-desktop-dirname.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    ## 3.设置git config
    echo -e "${hintStrProcessing}\n设置Git\n${normal}"
    echo -e "${hintStrProcessing}\nconfiguring Git\n${normal}"
    git config --global http.sslVerify false
    pipx install commitizen
    # userSelect "Installing all" y
    # if [[ $? == 0 ]]; then
    #     installApt full
    # else
    #     installApt
    # fi

    ## 4.安装apt包
    bash ./bin-for-install/01.install-apt-softwares.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    ## 5.安装字体
    bash ./bin-for-install/08.install-fonts.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi
    
    ## 6.语言区域设置
	source ./bin-for-install/03.set-locale.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    if [[ ! -f ${HOME}/.envrc ]];then
        echo " ">|${HOME}/.envrc
    fi
    
    alias cp='rsycn -ah --info=progress2'

    ## 7.安装neovim
    echo -e "${hintStrProcessing}Neovim installing${normal}"
    installNvimSnap

    ## 9.安装常用deb
    bash ./bin-for-install/10.install-commom-deb.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    ## 10.安装rime
    bash ./bin-for-install/11.install-rime.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

    ## 11.设置root下vimrc
    bash ./bin-for-install/06.set-vimrc.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

set +e
    ## 8.安装nodev20
    bash ./bin-for-install/09.install-node20.sh
    if [[ $? -ne 0 ]]; then
        echo -e "${red4}Error occured${normal}"
    	exit
    fi

set +e
}
main $@

echo -e "${hintStrSucceed}\e[1;5m安装完毕，请重启Shell。${normal}"
echo -e "          \e[1;5mScript executed successfully, Please relaunch shell.${normal}"
